package com.hfi.qinxiaobo151;

import org.junit.Test;

import java.text.NumberFormat;

/**
 * @author ChangLiang
 * @date 2018/9/3
 */
public class Item1_4 {
    //简单折扣计算
    public void calPrice(int price,int discount){
        float knockdownPrice =price * discount / 100.0F;
        System.out.println("简单折扣后的价格是："+formateCurrency(knockdownPrice));
    }

    //复杂多折扣计算
    public void calPrice(int price,int... discounts){
        float knockdownPrice = price;
        for(int discount:discounts){
            knockdownPrice = knockdownPrice * discount / 100;
        }
        System.out.println("复杂折扣后的价格是：" +formateCurrency(knockdownPrice));
    }

    //格式化成本地货币形式
    private String formateCurrency(float price){
        return NumberFormat.getCurrencyInstance().format(price/100);
    }

    @Test
    public void test() {
        Item1_4 client = new Item1_4();
        //499元的货物，打75折
        client.calPrice(49900, 75);
    }
}
